package com.wayhome.springframework.beans.factory.support;

import com.wayhome.springframework.beans.BeanException;
import com.wayhome.springframework.beans.factory.BeanFactory;
import com.wayhome.springframework.beans.factory.config.BeanDefinition;

/**
 * 继承了单例，实现beanFactory 是核心模板类
 */
public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements BeanFactory {

    public Object getBean(String beanName) throws BeanException {
        Object singleton = getSingleton(beanName);
        if (singleton != null) {
            return singleton;
        }
        BeanDefinition beanDefinition = getBeanDefinition(beanName);

        return createBean(beanName, beanDefinition);
    }
    protected abstract BeanDefinition getBeanDefinition(String beanName) throws BeanException;

    protected abstract Object createBean(String beanName, BeanDefinition beanDefinition) throws BeanException;
}
